var fs = require('fs');
var path = require('path');

const ENV = process.env.ENV = process.env.NODE_ENV.trim().toUpperCase();

fs.stat('OUTPUT/' + ENV, function (err, stat) {
    if (err) {
        console.log('there is no such file or path OUTPUT/' + ENV + '/*');
        throw err;
    }
    var sourceFile = path.join(__dirname, 'src/config/app.' + ENV.trim().toLowerCase() + '.config.js');
    var destPath = path.join(__dirname, 'OUTPUT/' + ENV + '/app.config.js');

    var readStream = fs.createReadStream(sourceFile).on('error', function (err) {
        console.log('create read stream error');
        throw err;
    });
    var writeStream = fs.createWriteStream(destPath).on('error', function (err) {
        console.log('create write stream error');
        throw err;
    });
    readStream.pipe(writeStream).on('error', function (err) {
        console.log('stream pipe error');
        throw err;
    });

});